package operations;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Add implements IOperation{
    public void work(BookList bookList){
        //添加图书
        System.out.println("添加图书");
        System.out.println("请输入添加的图书的名字：");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        System.out.println("请输入添加的图书的作者：");
        String author=scanner.nextLine();
        System.out.println("请输入添加的图书的价格：");
        int price=scanner.nextInt();

        scanner.nextLine();

        System.out.println("请输入添加的图书的类型：");
        String type=scanner.nextLine();

        Book book=new Book(name,author,price,type);
        //获取当前存放书的位置
        int curSize= bookList.getUsedSize();
        //把书放在有效位置
        bookList.setBooks(book,curSize);
        //书的有效个数+1
        bookList.setUsedSize(curSize+1);

    }
}
